package com.hfy.music.service.impl;

import com.hfy.model.Bo.UploadBo;
import com.hfy.music.mapper.UploadMapper;
import com.hfy.music.service.UploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import result.Result;

/**
 * @ author 韩
 * time: 2024/5/14 15:40
 */
@Service
public class UploadServiceImpl implements UploadService {

    @Autowired
    private UploadMapper uploadMapper;

    @Override
    public Result uploadMusic(UploadBo upload) {
//        // 更新sql
//        MusicPo uploadPo = BeanUtil.copyProperties(upload, MusicPo.class);
//        // 设置一下现在的日期
//        uploadPo.setCreateTime(LocalDate.now());
//        // 设置音频文件的路径名
//        String musicName = OSS_HTTPS_PREFIX + OSS_BUCKET_NAME + "."  + OSS_ENDPOINT + "/" + OSS_MUSIC_PREFIX + upload.getName() + "(" + upload.getMusician() + ")" + OSS_MUSIC_SUFFIX;
//        uploadPo.setMusic_url(musicName);
//        // 设置封面图片的路径名
//        String coverName = OSS_HTTPS_PREFIX + OSS_BUCKET_NAME + "."  + OSS_ENDPOINT + "/" + OSS_COVER_PREFIX + upload.getName() + "(" + upload.getMusician() + ")" + OSS_MUSIC_SUFFIX;
//        uploadPo.setCover(coverName);
//
//        // 在sql层绑定unique，唯一索引，当相同的歌曲被添加过的时候，会发生异常
//        try {
//            uploadMapper.uploadMusic(uploadPo);
//        } catch (Exception e) {
//            return Result.error("有相同歌曲被添加过了，如果音源不同建议更换乐曲名");
//        }

//        return Result.ok(uploadPo.getId());
        return Result.ok();
    }

    @Override
    public boolean rollbackRecord(Integer id) {
        boolean flag = uploadMapper.deleteTheRecord(id);
        return flag;
    }


}
